package com.sifeng.test;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class testCoop {
	
	public static void main(String[] args) {
		String coopId="1571295697004";
		String sigKey="w3ku3ekby71i1po8q3f69ii5dd1veb2c";
		String mblNo="15973132202";
		String reqTyp="21";
		String serFlg="1";//1��SIT 2��UAT 3������ 0:���Ļ�
//		test1(coopId,sigKey,mblNo,reqTyp,SERVICEserFlg);
		test2(coopId,sigKey,mblNo,reqTyp,serFlg);
	}
	
	//��ȡtoken
	public static void test1(String coopId,String sigKey,String mblNo,String reqTyp,String serFlg){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		//String REQ_TM = sdf.format(new Date());
		String REQ_TM = "20180912172409";
		
		String argReq = mblNo + REQ_TM + reqTyp+coopId+ sigKey;
		String sigVal = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.reset();
			md.update(argReq.getBytes("UTF-8"));
			byte[] md5= md.digest();
			sigVal = byteArrayToHex(md5);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String aa = "MBL_NO="+mblNo+"&REQ_TM="+REQ_TM+"&REQ_TYP="+reqTyp+"&COOP_ID="+coopId+"&SIG_VAL="+sigVal;
		if(serFlg.equals("1")){
			System.out.println("http://172.16.49.68:31021/sysmng/pug/CPUGPUB1/4440074.dow?" + aa);
		}else if(serFlg.equals("2")){
			System.out.println("http://172.16.49.218:31021/sysmng/pug/CPUGPUB1/4440074.dow?" + aa);  
		}else if(serFlg.equals("0")){
			System.out.println("http://172.16.49.180:31021/sysmng/pug/CPUGPUB1/4440074.dow?" + aa);  
		}else{
			System.out.println("http://ipos.10086.cn/pug/CPUGPUB1/4440074.dow?"+aa);
		}
	}
	
	//���ɵ����¼����
	public static void test2(String coopId,String sigKey,String mblNo,String reqTyp,String serFlg){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String REQ_TM = sdf.format(new Date());
		String ACCESS_TOKEN ="C23856FA177DD45E59F05544B637FCDC";
		
		String argReq = mblNo + REQ_TM + coopId + ACCESS_TOKEN + sigKey;
		String sigVal = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.reset();
			md.update(argReq.getBytes("UTF-8"));
			byte[] md5= md.digest();
			sigVal = byteArrayToHex(md5);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String aa = "MBL_NO="+mblNo+"&REQ_TM="+REQ_TM+"&COOP_ID="+coopId+"&ACCESS_TOKEN="+ACCESS_TOKEN+"&SIG_VAL="+sigVal;
		if(serFlg.equals("1")){
//			System.out.println("http://uat.cmpay.com/user/service/sso_get_login.xhtml?" + aa);  
		    System.out.println("http://172.16.49.68:31021/sysmng/pug/CPUGPUB1/4440084.dow?" + aa);  
		}else if(serFlg.equals("2")){
			System.out.println("http://uat.cmpay.com/user/service/sso_get_login.xhtml?" + aa);  
			System.out.println("http://172.16.49.218:31021/pug/CPUGPUB1/4440084.dow?" + aa);  
		}else if(serFlg.equals("0")){
			System.out.println("http://172.16.49.180:31021/sysmng/pug/CPUGPUB1/4440084.dow?" + aa);  
		}else{
			System.out.println("http://ipos.10086.cn/pug/CPUGPUB1/4440084.dow?"+aa);
		}
		//System.out.println("https://uat.cmpay.com/user/service/sso_get_login.xhtml?" + aa);  
	}
	
	//���Ի��Ѳ�ѯ
	public static void test3(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		String MBL_NO = "13667319020";
		String TTXN_TM = sdf.format(new Date());
		String TTXN_CNL="HWX";
	    String SIG_KEY="HWXb0125d0f01f2ffad";
		
		String argReq = MBL_NO + TTXN_TM + TTXN_CNL + SIG_KEY;
		String sigVal = "";
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.reset();
			md.update(argReq.getBytes("UTF-8"));
			byte[] md5= md.digest();
			sigVal = byteArrayToHex(md5);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		String aa = "MBL_NO="+MBL_NO+"&TTXN_TM="+TTXN_TM+"&TTXN_CNL="+TTXN_CNL+"&SIG_VAL="+sigVal;
		//System.out.println("https://uat.cmpay.com/user/service/sso_get_login.xhtml?" + aa);  
		System.out.println("http://ipos.10086.cn/pug/CPUGPUB1/4440010.dow?" + aa);  
	}
	
	public static String byteArrayToHex(byte[] bytes) {
		String retorno = "";
		if (bytes == null || bytes.length == 0) {
			return retorno;
		}
		for (int i = 0; i < bytes.length; i++) {
			byte valor = bytes[i];
			int d1 = valor & 0xF;
			d1 += (d1 < 10) ? 48 : 55;
			int d2 = (valor & 0xF0) >> 4;
			d2 += (d2 < 10) ? 48 : 55;
			retorno = retorno + (char) d2 + (char) d1;
		}
		return retorno;
	}
}
